package com.monlyu.action.log;

import java.io.File;
import java.lang.reflect.Array;

import javax.naming.directory.DirContext;

import com.monlyu.action.BaseAction;

/**
 * @since Fan Houjun 2009-3-25
 */
public class ViewLogAction extends BaseAction {

	public ViewLogAction() {
	}

	private File[] logs;

	public File[] getLogs() {
		return logs;
	}

	private String dir;

	public void setDir(String dir) {
		this.dir = dir;
	}

	public String execute() throws Exception {
		File dirFile = new File(System.getProperty("user.dir")
				+ "/WebRoot/logs");
		File[] temp = dirFile.listFiles();
		dirFile = new File(System.getProperty("user.dir") + "/logs");
		File[] logs1 = dirFile.listFiles();
		if (logs1 != null && logs1.length > 0) {
			int i = temp.length;
			logs = new File[temp.length + logs1.length];
			System.arraycopy(temp, 0, logs, 0, temp.length);
			for (int j = 0; j < logs1.length; j++) {
				logs[i + j] = logs1[j];
			}
		} else {
			logs = new File[temp.length];
			System.arraycopy(temp, 0, logs, 0, temp.length);
		}
		return view("viewLogs.jsp");
	}
}
